home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Source Code
/
Pascal
/
System
/
Sample Init
/
Sample with A4
/
Init.p
next >
Wrap
Text File
|
1997-02-01
|
3KB
|
164 lines
unit Init;
interface
{$MAIN}
procedure Main;
implementation
uses
Types, Files, Events, OSUtils, Resources, Memory, Processes, GestaltEqu, Traps, SegLoad,
PascalA4;
const
bad_rn = -32768;
const
CurAppNameAddr = $910;
FinderNameAddr = $2E0;
const
SharedDataGestalt = 'AsiX';
SDF_Fired_bit = 1;
SDF_Finished_bit = 3;
SDF_StartFinder_bit = 4;
type
SharedData = record
assimilator_datafork_rn: integer;
flags: longInt;
end;
SharedDataPtr = ^SharedData;
SharedDataHandle = ^SharedDataPtr;
SharedDataPtrPtr = ^SharedDataPtr;
var
old_patch_addr: ProcPtr;
shared_data: SharedData;
function RefNumToFSSpec (rn: integer; var fs: FSSpec): OSErr;
var
pb: FCBPBRec;
begin
pb.ioNamePtr := @fs.name;
pb.ioVRefNum := 0;
pb.ioRefNum := rn;
pb.ioFCBIndx := 0;
RefNumToFSSpec := PBGetFCBInfoSync(@pb);
fs.vRefNum := pb.ioFCBVRefNum;
fs.parID := pb.ioFCBParID;
end;
function FSpGetCatInfo (var fs: FSSpec; index: integer; var pb: CInfoPBRec): OSErr;
begin
pb.ioVRefNum := fs.vRefNum;
pb.ioDirID := fs.parID;
pb.ioNamePtr := @fs.name;
pb.ioFDirIndex := index;
FSpGetCatInfo := PBGetCatInfoSync(@pb);
end;
procedure LaunchFSSpec (var fs: FSSpec);
var
lpb: LaunchParamBlockRec;
junk: OSErr;
begin
lpb.launchBlockID := extendedBlock;
lpb.launchEPBLength := extendedBlockLen;
lpb.launchFileFlags := 0;
lpb.launchControlFlags := launchNoFileFlags;
lpb.launchAppSpec := @fs;
lpb.launchAppParameters := nil;
junk := LaunchApplication(@lpb);
end;
procedure MyInitMenus;
var
sd: SharedDataPtr;
gv: longint;
spec: FSSPec;
begin
sd := @shared_data;
if not BTST( sd^.flags, SDF_Finished_bit ) then begin
if (StringPtr(CurAppNameAddr)^ = StringPtr(FinderNameAddr)^) then begin
if not BTST( sd^.flags, SDF_Fired_bit ) then begin
BSET( sd^.flags, SDF_Fired_bit );
BSET( sd^.flags, SDF_StartFinder_bit );
if (Gestalt(gestaltOSAttr, gv) = noErr) & (BTST(gv, gestaltLaunchFullFileSpec)) then begin
if RefNumToFSSpec( sd^.assimilator_datafork_rn, spec ) = noErr then begin
LaunchFSSpec( spec );
{ NOT REACHED }
end;
end;
end;
ExitToShell;
end;
end;
end;
function MySetupA4: longint;
begin
MySetupA4 := SetUpA4;
end;
procedure MyPatch; asm;
begin
clr.l -(sp)
movem.l d0-d2/a0-a1,-(sp)
clr.l -(sp)
jsr MySetupA4
jsr MyInitMenus
move.l old_patch_addr,24(sp) { d0-d2, a0-a1, A4 }
move.l (sp)+, a4
movem.l (sp)+,d0-d2/a0-a1
rts
end;
function MyGestalt (selector: OSType; var response: longInt): OSErr;
var
a4: longint;
begin
{$unused(selector)}
a4 := SetUpA4;
response := longInt(@shared_data);
a4 := RestoreA4( a4 );
MyGestalt := noErr;
end;
procedure Main;
var
sd: SharedDataPtr;
junk: OSErr;
fs: FSSpec;
a4: longint;
begin
a4 := SetCurrentA4;
RememberA4;
DetachResource(Get1Resource('INIT', 128));
sd := @shared_data;
sd^.flags := 0;
sd^.assimilator_datafork_rn := bad_rn;
junk := NewGestalt(SharedDataGestalt, @MyGestalt);
if RefNumToFSSpec(CurResFile, fs) = noErr then begin
if FSpOpenDF(fs, fsRdPerm, sd^.assimilator_datafork_rn) <> noErr then begin
sd^.assimilator_datafork_rn := bad_rn;
end;
end;
old_patch_addr := ProcPtr(NGetTrapAddress(_InitMenus, ToolTrap));
NSetTrapAddress(@MyPatch, _InitMenus, ToolTrap);
a4 := RestoreA4(a4);
end;
end.